package com.example.myerp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.myerp.pojo.S_cell_house;
import com.example.myerp.mapper.S_cell_houseMapper;
import com.example.myerp.service.S_cell_houseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhuxingyu
 * @since 2021-08-11
 */
@Service
public class S_cell_houseServiceImpl implements S_cell_houseService {

    @Autowired
    private S_cell_houseMapper S_cell_houseMapper;


    @Override
    public IPage<S_cell_house> selectHosue(Long pageNum, Long pageSize) {
        Page<S_cell_house> page = new Page<S_cell_house>(pageNum,pageSize,true);
        page.setCurrent(pageNum);
        page.setSize(pageSize);

//        page.setTotal(S_cell_houseMapper.selectCount(new QueryWrapper<S_cell_house>()
//                .gt("store_id", 0)));


        return S_cell_houseMapper.selectHouse(page);
    }

    @Override
    public Integer updateHosue(Long storeId, String storeName) {
        S_cell_house hosue = new S_cell_house(storeId,storeName);
        UpdateWrapper<S_cell_house> up = new UpdateWrapper();
        up.eq("store_id",storeId);
        int update = S_cell_houseMapper.update(hosue, up);
        return update;
    }

    @Override
    public Long auto_HouseId() {
        return S_cell_houseMapper.auto_HouseId();
    }

    @Override
    public Integer addS_cellHouse(String storeName) {
        return S_cell_houseMapper.insert(new S_cell_house(null,storeName));
    }

    @Override
    public List<S_cell_house> selectList() {
        QueryWrapper<S_cell_house> wrapper = new QueryWrapper<S_cell_house>();
        wrapper.gt("store_id",0);
        List<S_cell_house> s_cell_houses = S_cell_houseMapper.selectList(wrapper);
        return s_cell_houses;
    }
}
